package com.l.web.common.sequence;

import org.l.qiao.Cluster;
import org.l.qiao.builder.Query;
import org.l.qiao.builder.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by 严秋旺 on 2016/11/8.
 */
@Service
public class SequenceService {

    private static final String SEQUENCE_DICTIONARY = "dictionary";

    @Autowired
    private SequenceDAO sequenceDAO;

    private long next(String id) {
        Query query = new Query(Sequence.ID, id);
        Update update = new Update();
        update.inc(Sequence.VALUE, 1);
        Cluster cluster = sequenceDAO.findAndModify(query, update);
        return cluster.getLong(Sequence.VALUE);
    }

    public long dictionaryNext() {
        return next(SEQUENCE_DICTIONARY);
    }

}
